package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.DTRequestDto;
import com.hualude.roadsign.dto.DTResponseDto;
import com.hualude.roadsign.dto.JsonMsgDto;
import com.hualude.roadsign.service.NoticeAddService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by pjn on 2017/3/3.
 */
@Controller
@RequestMapping("/rds_noticeadd")
public class NoticeAddController {
    @Resource
    private NoticeAddService noticeAddService;


    @RequestMapping(value = "/addNotice")
    @ResponseBody
    public JsonMsgDto addNotice(Integer createUserId, String noticeTitle, String noticeContext, String orgIds) {
        JsonMsgDto dto = new JsonMsgDto();
        try {
            dto.setJsonData(noticeAddService.addNotice(createUserId, noticeTitle, noticeContext, orgIds));
            dto.setIsSuccess(true);
        } catch (Exception e) {
            dto.setIsSuccess(false);
            e.printStackTrace();
        }
        return dto;
    }


    @RequestMapping(value = "/getNoticesended4DT")
    @ResponseBody
    public DTResponseDto getNoticesended4DT(DTRequestDto dtRequestDto) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = noticeAddService.getNoticesended4DT(dtRequestDto);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }


    @RequestMapping(value = "/getSelectNoticeSendedOrg")
    @ResponseBody
    public JsonMsgDto getSelectNoticeSendedOrg(Integer noticeId) {
        JsonMsgDto dto = new JsonMsgDto();
        try {
            dto.setJsonData(noticeAddService.getSelectNoticeSendedOrg(noticeId));
            dto.setIsSuccess(true);
        } catch (Exception e) {
            dto.setIsSuccess(false);
            e.printStackTrace();
        }
        return dto;
    }

    @RequestMapping(value = "/deleteNotice")
    @ResponseBody
    public JsonMsgDto deleteNotice(Integer userNoticeId) {
        JsonMsgDto dto = new JsonMsgDto();
        try {
            dto.setJsonData(noticeAddService.deleteNotice(userNoticeId));
            dto.setIsSuccess(true);
        } catch (Exception e) {
            dto.setIsSuccess(false);
            e.printStackTrace();
        }
        return dto;
    }

    @RequestMapping(value = "/deleteSelectNotice")
    @ResponseBody
    public JsonMsgDto deleteSelectNotice(String noticeIds) {
        JsonMsgDto dto = new JsonMsgDto();
        try {
            noticeAddService.deleteSelectNotice(noticeIds);
            dto.setIsSuccess(true);
        } catch (Exception e) {
            dto.setIsSuccess(false);
            e.printStackTrace();
        }
        return dto;
    }


    @RequestMapping(value = "/getOrgInfo4Notice")
    @ResponseBody
    public JsonMsgDto getOrgInfo4Notice() {
        JsonMsgDto dto = new JsonMsgDto();
        try {
            dto.setJsonData(noticeAddService.getOrgInfo4Notice());
            dto.setIsSuccess(true);
        } catch (Exception e) {
            dto.setIsSuccess(false);
            e.printStackTrace();
        }
        return dto;
    }


    @RequestMapping(value = "/getNoticeByUserId")
    @ResponseBody
    public JsonMsgDto getNoticeByUserId(Integer userId, Integer mCount, Integer mySize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(noticeAddService.getNoticeByUserId(userId, mCount, mySize));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

}
